<template>
	<!-- 同城按摩 -->
	<view>
		<view style="position: sticky;top: 0;background-color: #F5F5F5;">
			<view class="search">
				<input type="text" v-model="keyword" placeholder="请输入关键词搜索" />
				<text @click="C_search()">搜索</text>
			</view>
			<!-- <u-tabs :list="navlist" name='catename' :current="current" @change="change"></u-tabs> -->
		</view>
		
		<!-- list -->
		<view class="list">
			<view v-for="(item,index) in list" :key='index' @click="C_goShop(index)"> 
				<image :src="item.images[0]" mode="aspectFill"></image>
				<view>
					<view class="name">{{item.name}}</view>
					<view class="msg">{{item.city}}</view>
					<view class="s_b"> {{item.catename}} </view>
					<view>营业时间:{{item.business}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navlist: [],
				current: null,
				
				list:[],
				keyword:'',
				pageNum:1
			};
		},
		onLoad(o) {
			this.optionId = o.id
		},
		onShow() {
			this.def_menu()
		},
		onReachBottom(){
			this.def_list(this.pageNum++)
		},
		watch:{
			current(idx){
				this.optionId = this.navlist[idx].id
				
				this.def_list()
			}
		},
		methods:{
			C_search(){
				this.list = []
				this.$u.post('/local/localshop',{
					page:1,
					limit:100,
					localcate_id:this.optionId,
					city:this.vuex_city,
					keyword:this.keyword
				}).then(res=>{
					let {count , list } = res.data
					console.log(res.data);
					this.list = list
				})
			},
			async def_menu(){
				let classify = await this.$u.api.indexlocalcate()
				classify.data.forEach((item,index)=>item.id == this.optionId?this.current = index:'')
				this.navlist = classify.data
			},
			def_list(){
				console.log(123);
				this.$u.post('/local/localshop',{
					page:this.pageNum,
					limit:3,
					localcate_id:this.optionId,
					city:this.vuex_city,
					keyword:this.keyword
				}).then(res=>{
					let {count , list } = res.data
					if(list.length == 0){
						this.$u.toast('没有跟多数据了')
						return
					}
					if(this.pageNum == 1){
						this.list = list
					}else{
						this.list = this.list.concat(list)
					}
				})
			},
			C_goShop(){
				uni.navigateTo({
					url:'./shop/shop'
				})
			},
			change(index) {
				this.current = index;
			}
		}
	}
</script>

<style lang="scss">
	.search{
		display: flex;
		align-items: center;
		margin-right: 5%;
		input{
			background-color: #FFFFFF;
			height: 70rpx;
			padding-left: 80rpx;
			border-radius: 20rpx;
			margin: 20rpx 5%; 
			flex: 1;
		}
		text{
			height: 60rpx;
			line-height: 60rpx;
			padding: 0 30rpx;
			border-radius: 20rpx;
			background-color: #3681FF;
			color: #FFFFFF;
		}
	}
	
	.list{
		width: 95%;
		margin: 20rpx auto;
		font-size: 24rpx;
		color: gray;
		>view{
			background-color: #FFFFFF;
			margin-bottom: 20rpx;
			display: flex;
			// align-items: center;
			padding: 30rpx;
			border-radius: 10rpx;
			image{
				width: 150rpx;
				height: 150rpx;
				margin-right: 20rpx;
				border-radius: 10rpx;
			}
			>view{
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				min-width: 60%;
				.msg{
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					display: block;
				}
				.name{
					color: #333333;
					font-weight: bold;
					font-size: 30rpx;
				}
				.s_b{
					display: flex;
					justify-content: space-between;
				}
			}
		}
	}
</style>
